package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.UserBean;
import com.project.mapper.IUserMapper;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserMapper mapper;
    @Override
    public UserBean login(String userName, String pwd) {
        return mapper.login(userName, pwd);
    }

    @Override
    public PageInfo<UserBean> findByItem(int pageNO, String userName) {
        PageHelper.startPage(pageNO, PAGESIZE);
        PageInfo<UserBean> pageInfo = PageInfo.of(mapper.findByItem(userName));
        return pageInfo;
    }

    @Override
    public void addUser(UserBean user, int[] roleArray) {
        mapper.addUser(user);
        mapper.addUserRole(user.getId(), roleArray);
    }

    @Override
    public void delUser(int id) {
        mapper.delUser(id);
    }

    @Override
    public UserBean findById(int id) {

        return mapper.findById(id);
    }

    @Override
    public void updateUserGrade(int id, int[] roleArray) {
        mapper.updateUserGrade(id, roleArray);
    }
}
